package com.brainhealth.web.controller.common;


import com.brainhealth.common.core.domain.AjaxResult;
import com.brainhealth.common.utils.file.FileUtils;
import com.brainhealth.customer.domain.vo.SysFileVO;
import com.brainhealth.customer.service.IMinioService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/minio")
public class MinioController
{

    @Resource
    IMinioService minioService;

    /**
     * 文件上传请求
     */
    @PostMapping("upload")
    public AjaxResult upload(HttpServletRequest request, MultipartFile[] file)
    {
        try
        {
            // 上传并返回访问地址
            List<SysFileVO> sysFileList = minioService.uploadFile(file, request.getHeader("source"));
            return AjaxResult.success(sysFileList);
        } catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }
}
